package cn.hznc.controller.toolAnalyze;

import cn.hznc.aspect.BusinessType;
import cn.hznc.aspect.Log;
import cn.hznc.controller.service.toolAnalyze.ToolConsumptionandUsageAnalysisService;
import cn.hznc.domain.entity.ToolConsumptionandUsageAnalysisEntity;
import cn.hznc.domain.entity.ToolLifeAnalyzeEntity;
import cn.hznc.domain.entity.TypeEntity;
import cn.hznc.domain.request.toolAnalyze.ToolConsumptionReq;
import cn.hznc.domain.request.toolAnalyze.ToolConsumptionandUsageAnalysisReq;
import cn.hznc.domain.request.toolAnalyze.ToolLifeAnalyzeReq;
import cn.hznc.domain.response.PageResult;
import cn.hznc.domain.response.ResponseBody;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/toolConsumptionandUsageAnalysis")
public class ToolConsumptionandUsageAnalysisController {
    @Resource
    private ToolConsumptionandUsageAnalysisService toolConsumptionandUsageAnalysisService;

    @RequestMapping(value = "/queryToolConsumptionandUsageAnalysis", method = RequestMethod.POST)
    public ResponseBody<PageResult<ToolConsumptionandUsageAnalysisEntity>> queryToolConsumptionandUsageAnalysis(@RequestBody ToolConsumptionandUsageAnalysisReq toolConsumptionandUsageAnalysisReq) {
        return ResponseBody.success(toolConsumptionandUsageAnalysisService.queryToolConsumptionandUsageAnalysis(toolConsumptionandUsageAnalysisReq));
    }

    @RequestMapping(value = "/queryToolConsumption", method = RequestMethod.POST)
    public ResponseBody<PageResult<ToolConsumptionandUsageAnalysisEntity>> queryToolConsumption(@RequestBody ToolConsumptionReq toolConsumptionReq) {
        return ResponseBody.success(toolConsumptionandUsageAnalysisService.queryToolConsumption(toolConsumptionReq));
    }

    @RequestMapping(value = "/deleteTypeById", method = RequestMethod.GET)
    public ResponseBody test1(@RequestParam Integer id){
        return ResponseBody.success(toolConsumptionandUsageAnalysisService.deleteTypeById(id));
    }

    @RequestMapping(value = "/queryAllType", method = RequestMethod.GET)
    public ResponseBody<List<TypeEntity>> test2(){
        return ResponseBody.success(
                toolConsumptionandUsageAnalysisService.queryAllType()
        );
    }

    @RequestMapping(value = "/insertType", method = RequestMethod.GET)
    @Log(title = "新增自定义类型" , businessType = BusinessType.INSERT)
    public ResponseBody test3(@RequestParam(defaultValue = "0") Integer parentId,
                              @RequestParam String typeName){
        try{
            toolConsumptionandUsageAnalysisService.insertType(parentId,typeName);
            return ResponseBody.success();
        }catch (Exception ex){
            return ResponseBody.error(ex.getMessage(),ex.getMessage());
        }
    }

    @RequestMapping(value = "/updateType", method = RequestMethod.GET)
    @Log(title = "编辑自定义类型" , businessType = BusinessType.UPDATE)
    public ResponseBody test4(@RequestParam Integer id,
                              @RequestParam String typeName){
        try{
            toolConsumptionandUsageAnalysisService.updateType(id,typeName);
            return ResponseBody.success();
        }catch (Exception ex){
            return ResponseBody.error(ex.getMessage(),ex.getMessage());
        }
    }
}
